package 笔试.顺丰;

import java.util.ArrayList;
import java.util.Scanner;

public class 相邻的整除数字序列 {
    // ac
    static class Solution {
        public static void dfs(int[] room, int i, boolean[] visited, ArrayList<Integer> cur,
                               ArrayList<ArrayList<Integer>> res, int dept) {
            if (dept != 1) {
                int num1 = room[i];
                int num2 = cur.get(cur.size() - 2);
                if (num1 % num2 != 0 || num2 % num1 != 0) {
                    return;
                }
            }
            if (dept == room.length) {
                res.add(new ArrayList<>(cur));
                return;
            }
            for (int k = 0; k < room.length; k++) {
                if (!visited[k]) {
                    visited[k] = true;
                    cur.add(room[k]);
                    dfs(room, k, visited, cur, res, dept + 1);
                    cur.remove(cur.size() - 1);
                    visited[k] = false;
                }
            }
        }

        public void solve(int[] room, int n) {
            boolean[] visited = new boolean[n];
            ArrayList<Integer> cur = new ArrayList<>();
            ArrayList<ArrayList<Integer>> res = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                visited[i] = true;
                cur.add(room[i]);
                dfs(room, i, visited, cur, res, 1);
                cur.remove(cur.size() - 1);
                visited[i] = false;
            }
            System.out.println(res.size());
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] room = new int[n];
        for (int i = 0; i < n; i++) {
            room[i] = sc.nextInt();
        }
        Solution solution = new Solution();
        solution.solve(room, n);
    }
}
